package ngames.com.sushitv.tools;

import android.content.Context;
import android.text.TextUtils;

import java.util.HashMap;

/**
 * Created by Jeffrey on 2016/7/27.
 */
public class NetUtil {
    public static String DEVICE_ID = null;

    public static String addCommonParameters(Context context, String url) {
        if (TextUtils.isEmpty(DEVICE_ID)) {
            DEVICE_ID = Utils.getDeviceId(context);
        }
        StringBuilder sb = new StringBuilder();
        sb.append(url);
        sb.append("uuid=").append(DEVICE_ID).append("&");
        sb.append("timestamp=").append(System.currentTimeMillis()).append("&");
        sb.append("token=").append(Constants.APP_TOKEN).append("&");
        sb.append("device=").append(Constants.DEVICE).append("&");
        sb.append("api_version=").append(Constants.API_VERSION).append("&");
        sb.append("app_version=").append(Constants.APP_VERSION);
        return sb.toString();
    }

    public static HashMap<String, String> addCommonParameters(Context context, HashMap<String, String> params) {
        if (TextUtils.isEmpty(DEVICE_ID)) {
            DEVICE_ID = Utils.getDeviceId(context);
        }
        if (params == null) {
            params = new HashMap<>(6);
        }
        params.put("uuid", DEVICE_ID);
        params.put("timestamp", Long.toString(System.currentTimeMillis()));
        params.put("token", Constants.APP_TOKEN);
        params.put("device", Constants.DEVICE);
        params.put("api_version", Constants.API_VERSION);
        params.put("app_version", Constants.APP_VERSION);
        return params;
    }
}
